<?php

namespace App\V3\V3_2_7\Controllers;

use App\V3\V3_2_7\Services\VipSettingService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

class VipSettingController extends BaseController
{
//    public function __construct(Request $request)
//    {
//        parent::__construct($request);
//
//        if($this->getMainUserId() != 1) {
//            echo json_encode([
//                'code' => 1,
//                'msg' => '权限不足，非超级管理员无法操作',
//                'data' => ''
//            ]);
//            die;
//        }
//    }

    /**
     * vip功能列表
     * AUTHOR  : Sun Wu
     * DateTime: 2022/8/4 15:19
     * @return \Illuminate\Http\JsonResponse
     */
     public function index()
     {
         return $this->success(
             VipSettingService::index()
         );
     }

     public function add(Request $request)
     {
         //参数验证
         $validator = Validator::make($data = $request->all(), [
             'open_vip_cost' =>'required|numeric|min:0|max:99999.99',//开通vip功能所需费用
             'album_amount' =>'required|integer|min:-1|max:9999',//彩页数量
             'album_page_amount' =>'required|integer|min:-1|max:9999',//彩页页数
             'empty_bill_amount' =>'required|integer|min:-1|max:9999',//空白单数
             'special_seal' =>'required|integer|min:-1|max:9999',//专用印章数
             'one_key_album_times' =>'required|integer|min:-1|max:9999',//一键生成画册次数
             'express_check_times' =>'required|integer|min:-1|max:9999',//快递查询次数
             'account_storage' =>'required|integer|min:0',//存储空间
             'first_charge_price' =>'required|min:0',//首充金额
             'sub_account_number' =>'required|integer|min:-1|max:9999',//可创建子账号数
             'clear_watermark_or_not' => [
                 'required',
                 'integer',
                 Rule::in([0,1]),
             ],//去除水印;0:否;1:是;
         ], [
             'first_charge_price.required' => '参数`首充金额`缺失',
             'first_charge_price.min' => '参数`首充金额`最小仅能为0',
             'open_vip_cost.required' => '参数`开通vip所需费用`缺失',
             'open_vip_cost.numeric' => '参数`开通vip所需费用`仅能为数字',
             'open_vip_cost.min' => '参数`开通vip所需费用`最小仅能为0',
             'open_vip_cost.max' => '参数`开通vip所需费用`最大仅能为99999.99',
             'album_amount.required' => '参数`彩页数量`丢失',
             'album_page_amount.required' => '参数`彩页页数`丢失',
             'sub_account_number.required' => '参数`可创建子账号数`丢失',
             'empty_bill_amount.required' => '参数`空白单数`丢失',
             'special_seal.required' => '参数`专用印章数`丢失',
             'one_key_album_times.required' => '参数`一键生成画册次数`丢失',
             'express_check_times.required' => '参数`快递查询次数`丢失',
             'account_storage.required' => '参数`存储空间`丢失',
             'clear_watermark_or_not.required' => '参数`去除水印`丢失',
             'album_amount.integer' => '参数`彩页数量`只能为整数',
             'album_page_amount.integer' => '参数`彩页页数`只能为整数',
             'empty_bill_amount.integer' => '参数`空白单数`只能为整数',
             'special_seal.integer' => '参数`专用印章数`只能为整数',
             'one_key_album_times.integer' => '参数`一键生成画册次数`只能为整数',
             'express_check_times.integer' => '参数`快递查询次数`只能为整数',
             'account_storage.integer' => '参数`存储空间`只能为整数',
             'clear_watermark_or_not.integer' => '参数`去除水印`只能为整数',
             'album_amount.min' => '参数`彩页数量`最小只能为-1',
             'album_page_amount.min' => '参数`彩页页数`最小只能为-1',
             'empty_bill_amount.min' => '参数`空白单数`最小只能为-1',
             'special_seal.min' => '参数`专用印章数`最小只能为-1',
             'one_key_album_times.min' => '参数`一键生成画册次数`最小只能为-1',
             'express_check_times.min' => '参数`快递查询次数`最小只能为-1',
             'account_storage.min' => '参数`存储空间`最小只能为0',
             'album_amount.max' => '参数`彩页数量`最大只能为9999',
             'album_page_amount.max' => '参数`彩页页数`最大只能为9999',
             'empty_bill_amount.max' => '参数`空白单数`最大只能为9999',
             'special_seal.max' => '参数`专用印章数`最大只能为9999',
             'one_key_album_times.max' => '参数`一键生成画册次数`最大只能为9999',
             'express_check_times.max' => '参数`快递查询次数`最大只能为9999',
             'clear_watermark_or_not.in' => '参数`去除水印`不合法'
         ]);

         //参数错误响应
         if ($info = $validator->errors()->first()) {
             return $this->fail('', $info);
         }

         $data['account_storage'] = $data['account_storage'] * 1024 *1024;

         $data['created_at'] = time();
         $this->log('配置vip功能内容', $data, '配置成功！');
         return $this->success(
             VipSettingService::add($data)
         );
     }

     public function edit(Request $request)
     {
         //参数验证
         $validator = Validator::make($data = $request->all(), [
             'id' => 'required',
             'is_vip' => [
                 Rule::in([0,1])
             ],
             'first_charge_price' =>'required|min:0',//首充金额
             'open_vip_cost' =>'required|numeric|min:0|max:99999.99',//开通vip功能所需费用
             'album_amount' =>'required|integer|min:-1|max:9999',//彩页数量
             'album_page_amount' =>'required|integer|min:-1|max:9999',//彩页页数
             'empty_bill_amount' =>'required|integer|min:-1|max:9999',//空白单数
             'special_seal' =>'required|integer|min:-1|max:9999',//专用印章数
             'one_key_album_times' =>'required|integer|min:-1|max:9999',//一键生成画册次数
             'express_check_times' =>'required|integer|min:-1|max:9999',//快递查询次数
             'sub_account_number' =>'required|integer|min:-1|max:9999',//可创建子账号数
             'account_storage' =>'required|integer|min:0',//存储空间
             'clear_watermark_or_not' => [
                 'required',
                 'integer',
                 Rule::in([0,1]),
             ],//去除水印;0:否;1:是;
         ], [
             'first_charge_price.required' => '参数`首充金额`缺失',
             'first_charge_price.min' => '参数`首充金额`最小仅能为0',
             'sub_account_number.required' => '参数`可创建子账号数`丢失',
             'id.required' => '参数`id`缺失',
             'vip_title.required' => '参数标题不能为空',
             'open_vip_cost.required' => '参数`开通vip所需费用`缺失',
             'open_vip_cost.numeric' => '参数`开通vip所需费用`仅能为数字',
             'open_vip_cost.min' => '参数`开通vip所需费用`最小仅能为0',
             'open_vip_cost.max' => '参数`开通vip所需费用`最大仅能为99999.99',
             'album_amount.required' => '参数`彩页数量`丢失',
             'album_page_amount.required' => '参数`彩页页数`丢失',
             'empty_bill_amount.required' => '参数`空白单数`丢失',
             'special_seal.required' => '参数`专用印章数`丢失',
             'one_key_album_times.required' => '参数`一键生成画册次数`丢失',
             'express_check_times.required' => '参数`快递查询次数`丢失',
             'account_storage.required' => '参数`存储空间`丢失',
             'clear_watermark_or_not.required' => '参数`去除水印`丢失',
             'album_amount.integer' => '参数`彩页数量`只能为整数',
             'album_page_amount.integer' => '参数`彩页页数`只能为整数',
             'empty_bill_amount.integer' => '参数`空白单数`只能为整数',
             'special_seal.integer' => '参数`专用印章数`只能为整数',
             'one_key_album_times.integer' => '参数`一键生成画册次数`只能为整数',
             'express_check_times.integer' => '参数`快递查询次数`只能为整数',
             'account_storage.integer' => '参数`存储空间`只能为整数',
             'clear_watermark_or_not.integer' => '参数`去除水印`只能为整数',
             'album_amount.min' => '参数`彩页数量`最小只能为-1',
             'album_page_amount.min' => '参数`彩页页数`最小只能为-1',
             'empty_bill_amount.min' => '参数`空白单数`最小只能为-1',
             'special_seal.min' => '参数`专用印章数`最小只能为-1',
             'one_key_album_times.min' => '参数`一键生成画册次数`最小只能为-1',
             'express_check_times.min' => '参数`快递查询次数`最小只能为-1',
             'account_storage.min' => '参数`存储空间`最小只能为0',
             'album_amount.max' => '参数`彩页数量`最大只能为9999',
             'album_page_amount.max' => '参数`彩页页数`最大只能为9999',
             'empty_bill_amount.max' => '参数`空白单数`最大只能为9999',
             'special_seal.max' => '参数`专用印章数`最大只能为9999',
             'one_key_album_times.max' => '参数`一键生成画册次数`最大只能为9999',
             'express_check_times.max' => '参数`快递查询次数`最大只能为9999',
             'clear_watermark_or_not.in' => '参数`去除水印`不合法',
             'is_vip.in' => '参数`是否为特权`不合法'
         ]);

         //参数错误响应
         if ($info = $validator->errors()->first()) {
             return $this->fail('', $info);
         }

         $data['account_storage'] = $data['account_storage'] * 1024 *1024;

         $this->log('修改vip功能内容', $data, '修改成功！');
         return response()->json(
             VipSettingService::edit($data)
         );
     }

     public function detail(Request $request)
     {
         //参数验证
         $validator = Validator::make($data = $request->all(), [
             'id' => 'required',
         ], [
             'id.required' => '参数`id`缺失',
         ]);

         //参数错误响应
         if ($info = $validator->errors()->first()) {
             return $this->fail('', $info);
         }

         return response()->json(
             VipSettingService::detail($data['id'])
         );
     }
}
